/*
 * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
 * Use of this source code is governed by a MIT license that can be
 * found in the LICENSE file.
 */

#pragma once

#include "RNOH/CppComponentInstance.h"
#include "LinearGradientStackNode.h"
#include "generated/react/renderer/components/react_native_linear_gradient/Props.h"
#include "generated/RNOH/generated/components/BaseRNLinearGradientComponentInstance.h"

namespace rnoh {
class LinearGradientComponentInstance : public BaseRNLinearGradientComponentInstance {
    using Super = BaseRNLinearGradientComponentInstance;

private:
    LinearGradientStackNode m_stackNode;
    std::vector<facebook::react::SharedColor> m_colors;
    facebook::react::Float m_angle;
    bool m_useAngle;
    std::vector<facebook::react::Float> m_locations;
    facebook::react::Point m_startPoint;
    facebook::react::Point m_endPoint;
    facebook::react::Point m_angleCenter;
    std::vector<float> m_stops;
    void getLinearGradient();
    void computeStops();

public:
    explicit LinearGradientComponentInstance(Context context);

    void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
    void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;

    LinearGradientStackNode &getLocalRootArkUINode() override;

    void onPropsChanged(SharedConcreteProps const &props) override;

    facebook::react::Float computeAngle(facebook::react::Point const &start, facebook::react::Point const &end);
};
} // namespace rnoh
